package com.ghy.text;

import com.ghy.mapper.OrderMapper;
import com.ghy.entity.EbOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;


@RunWith(SpringJUnit4ClassRunner.class)
//导入 spring 的配置文件
@ContextConfiguration("classpath:xml/spring-dao.xml")
public class OrderTest {
    @Autowired
    OrderMapper orderMapper;
    @Test
    public void testOrderPage(){
        int page =1;//查询第 1 页
        int pageSize= 3;//每页 3 条
        // alt+Enter
        List<EbOrder> order = orderMapper.findByPage((page - 1) * pageSize, pageSize);
        System.out.println(order);
    }
    @Test
    public void testOrderSave(){
        EbOrder eoOrder = new EbOrder();
        eoOrder.setEoUserId("今天心情正好");
        eoOrder.setEoUserName("又遇到bug");
        eoOrder.setEoUserAddress("解决");
        eoOrder.setEoCreateTime(new Date(2003));
        eoOrder.setEoCost(new BigDecimal(77));
        eoOrder.setEoStatus(10);
        eoOrder.setEoType(11);
        int result = orderMapper.save(eoOrder);
        System.out.println("result-:"+result);
    }
    @Test
    public void testOrderDelete(){
        int result = orderMapper.remove(748);
        System.out.println("result:"+result);
    }
    @Test
    public void testOrderUpdate(){
        EbOrder eoOrder = new EbOrder();
        eoOrder.setEoUserId("今天心情正好");
        eoOrder.setEoUserName("又遇到bug");
        eoOrder.setEoUserAddress("解决");
        eoOrder.setEoCreateTime(new Date(2003));
        eoOrder.setEoCost(new BigDecimal(77));
        eoOrder.setEoStatus(10);
        eoOrder.setEoType(11);
        //调用更新的方法
        int result = orderMapper.updateByPrimaryKey(eoOrder);
        System.out.println("result:"+result);

    }

    @Test
    public void testGetMaxPage(){
        Integer maxPage = orderMapper.getMaxPage(4);
        System.out.println("maxPage="+maxPage);
    }
    @Test
    public void testSelectOne(){
        System.out.println(orderMapper.selectOne(597));
    }
    @Test
    public void testOrderNamePage(){
        int page =1;//查询第 1 页
        int pageSize= 3;//每页 3 条
        // alt+Enter
        System.out.println(orderMapper.listByNamePage((page - 1) * pageSize, pageSize,"小乖"));
    }
}

